package com.ming.attendance.mapper;

import com.ming.attendance.po.AttendanceEvent;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AttendanceEventMapper {
    // 创建打卡事件
    int createEvent(AttendanceEvent event);

    // 修改事件
    int updateEvent(AttendanceEvent event);

    // 获取事件
    AttendanceEvent getEvent(String eventid);

    // 根据openid获取所有相关的event事件
    @Select("SELECT * FROM attendance_event\n" +
            "WHERE eventid IN (\n" +
            "    SELECT eventid FROM event_user\n" +
            "    WHERE openid = #{openid}\n" +
            ")")
    List<AttendanceEvent> getEventsByOpenid(String openid);

    // 删除事件
    @Delete("DELETE FROM `attendance_event` WHERE eventid = #{eventid}")
    int deleteEvent(AttendanceEvent eventid);
}
